home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 328 / v_m_hdwr.inc < prev    next >
Encoding:
Text File  |  1988-10-29  |  19.6 KB  |  615 lines

  1.  
  2. /***************************************************************************
  3.  
  4.    V_M_HDWR.INC
  5.  
  6.    include file for V_M_6502.C
  7.  
  8.    This file contains the hardware emulation routines.
  9.  
  10.    November 12, 1986  0:00
  11.  
  12.  ***************************************************************************/
  13.  
  14. /* the following declarations are here because they are also used by the
  15.    hardware service routines as well as by V_M_OPS.INC
  16.  */
  17.  
  18.   /* status bits of the P register: (6502)  NV_BDIZC */
  19.  
  20. #define NBIT 0x80
  21. #define VBIT 0x40
  22. #define BBIT 0x10
  23. #define DBIT 0x08
  24. #define IBIT 0x04
  25. #define ZBIT 0x02
  26. #define CBIT 0x01
  27.  
  28.   /* status bits of the CCR register: (68000)  BDIXNZVC */
  29.  
  30. #define BITN 0x08
  31. #define BITV 0x02
  32. #define BITB 0x80
  33. #define BITD 0x40
  34. #define BITI 0x20
  35. #define BITZ 0x04
  36. #define BITC 0x01
  37. #define BITX 0x10
  38.  
  39. #define DBUS    D0
  40. #define IR      D0
  41. #define REGA    D1
  42. #define REGX    D2
  43. #define REGY    D3
  44. #define REGSP   D4
  45. #define REGPC   D5
  46. #define REGST   D6
  47. #define REGEA   D7
  48.  
  49.  
  50. #define REGEMUL A0     /* constant pointer to emul:   */
  51. #define REGMEA  A1     /* pointer to mem[ea] */
  52. #define REGMPC  A2     /* pointer to mem[pc] */
  53. #define REGSTAT A3     /* pointer to stat[0] */
  54. #define GLOBAL  A4
  55. #define REGOPS  A5     /* constant pointer to vector table */
  56. #define LOCAL   A6
  57. #define SP      A7
  58.  
  59. #define GRAPHICS 1
  60. #define TEXT     2
  61. #define FULLGRAF 4
  62. #define SPLITSCR 8
  63. #define PAGE1    16
  64. #define PAGE2    32
  65. #define LORES    64
  66. #define HIRES    128
  67.  
  68. #define SETREAD   ADDQ.W #1,isread(A4)
  69. #define SETWRITE  CLR.W  isread(A4)
  70. #define TESTWRITE TST.W  isread(A4)
  71.  
  72. #define SAVEREGS MOVEM.L D1-D7/A0-A3/A5,-(SP)
  73. #define LOADREGS MOVEM.L (SP)+,D1-D7/A0-A3/A5
  74.  
  75. extern
  76.   emul_serv(),
  77.   nul()  , w0400(), w0800(), w2000(), w4000(), sC000(), sC010(), sC030(),
  78.   sC050(), sC051(), sC052(), sC053(), sC054(), sC055(), sC056(), sC057()
  79.  ;
  80.  
  81. int (*serv_hrdw[256])() = {    /* array of pointers to 256 service routines */
  82.  
  83.   nul  , w0400, w0800, w2000, w4000, nul  , nul  , nul  ,  /* 128 write */
  84.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,  /* no read */
  85.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  86.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  87.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  88.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  89.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  90.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  91.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,  /* no read */
  92.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  93.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  94.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  95.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  96.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  97.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  98.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  99.   sC000, sC010, sC030, sC050, sC051, sC052, sC053, sC054,  /* 128 read */
  100.   sC055, sC056, sC057, nul  , nul  , nul  , nul  , nul  ,  /* and write */
  101.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  102.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  103.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  104.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  105.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  106.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  107.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  108.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  109.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  110.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  111.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  112.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  113.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul  ,
  114.   nul  , nul  , nul  , nul  , nul  , nul  , nul  , nul
  115.  } ;
  116.  
  117. /* The following are variables required for the service routines */
  118.  
  119. int videomode,            /* state of video chip */
  120.     isread ,              /* nonzero = read, zero = write */
  121.     tempsound ;
  122. char keyboard,            /* value of keyboard register */
  123.      scrch ;              /* character to plot */
  124. char *font,               /* pointer to 8x8 system font */
  125.      *exitptr ;           /* pointer to exit_emul */
  126.  
  127. int baddr1[25] = {
  128.     0, 1280, 2560, 3840, 5120, 6400, 7680, 8960,
  129.     10240, 11520, 12800, 14080, 15360, 16640, 17920, 19200, 20480,
  130.     21760, 23040, 24320, 25600, 26880, 28160, 29440, 30720
  131.    } ;
  132.  
  133. int baddr2[25] = {
  134.     0, 640, 1280, 1920, 2560, 3200, 3840, 4480, 5120, 5760, 6400, 7040,
  135.     7680, 8320, 8960, 9600, 10240, 10880, 11520, 12160, 12800, 13440, 14080,
  136.     14720, 15360
  137.    } ;
  138.  
  139.  
  140.      /* initialize the stat[] array and set defaults for power on */
  141. InitMachine() {
  142.  
  143.   for (ea=0; ea; *(mem+ea++)=0) ;  /* clear out main memory */
  144.   for (ea=0; ea; stat[ea++]=0) ;   /* clear out stat array */
  145.  
  146.   for (ea=1024; ea<2048; ea++)
  147.      if ( (ea&0x7F) < 120) stat[ea]=1 ;   /* text page 1 */
  148.  
  149.   for (ea=2048; ea<3072; ea++)
  150.      if ( (ea&0x7F) < 120) stat[ea]=2 ;   /* text page 2 */
  151.  
  152.   for (ea=8192; ea<16384; ea++)
  153.      if ( (ea&0x7F) < 120) stat[ea]=3 ;   /* hires page 1 */
  154.  
  155.   for (ea=16384; ea<24576; ea++)
  156.      if ( (ea&0x7F) < 120) stat[ea]=4 ;   /* hires page 2 */
  157.  
  158.   stat[0xC000] = 128 ;     /* keyboard register */
  159.   stat[0xC010] = 129 ;     /* keyboard strobe */
  160.  
  161.   stat[0xC030] = 130 ;     /* speaker */
  162.  
  163.   stat[0xC050] = 131 ;     /* graphics switch */
  164.   stat[0xC051] = 132 ;     /* text switch */
  165.   stat[0xC052] = 133 ;     /* full screen switch */
  166.   stat[0xC053] = 134 ;     /* split screen switch */
  167.   stat[0xC054] = 135 ;     /* page 1 switch */
  168.   stat[0xC055] = 136 ;     /* page 2 switch */
  169.   stat[0xC056] = 137 ;     /* lo-res switch */
  170.   stat[0xC057] = 138 ;     /* hi-res switch */
  171.  
  172.   videomode = TEXT|PAGE1|HIRES|FULLGRAF ; /* initial power on text mode */
  173.  
  174.   InitPrint(mode) ;
  175.  
  176.  }           /* END OF INIT */
  177.  
  178.  
  179. dummy() {  /* This function is never called.
  180.               It's purpose is to allow the 68000 routines to pop into
  181.               C once in a while.
  182.               Therefore they must be inside a C function.   */
  183.  
  184.  
  185.          /* emul_serv is called whenever a read/write access is attempted
  186.             to non-RAM memory locations, such as ROM or hardware registers.
  187.  
  188.             i.e. the status byte was non-zero.
  189.  
  190.             when status bytes are >=$80 (write-only)
  191.             REGEA points to memory to read with D0
  192.             this routine ends with JMP (REGEMUL) when writing
  193.             and RTS when reading
  194.  
  195.             when status bytes are <> 0  (read and write)
  196.             REGEA points to memory to write with D0
  197.             byte to poke is in high byte of DBUS
  198.             this routine ends with JMP (REGEMUL)
  199.           */
  200.  asm {
  201.  
  202.  emul_serv:
  203.         ANDI.W  #0x00FF,IR                 /* clear out bits 8..15 */
  204.         ADD.W   IR,IR
  205.         ADD.W   IR,IR                      /* calculate offset */
  206.         LEA     serv_hrdw(GLOBAL),REGMEA   /* get start of vector table */
  207.         MOVE.L  0(REGMEA,IR.W),REGMEA      /* calculate correct vector */
  208.         JMP     (REGMEA)                   /* jump through it */
  209.  
  210.  
  211.   nul:       /* should never execute! but just in case */
  212.         JMP     (REGEMUL)
  213.  
  214.  
  215.   w0400:     /* handler for text page 1 */
  216.         SWAP    DBUS                       /* get character */
  217.         MOVE.L  REGEA,REGMEA
  218.         MOVE.B  DBUS,(REGMEA)              /* do the actual write to memory */
  219.         MOVE.B  DBUS,scrch(GLOBAL)         /* and to global variable */
  220.  
  221.         MOVE.W  REGEA,ea(GLOBAL)           /* let C know where to write */
  222.         SAVEREGS                           /* save 6502 enviornment */
  223.   }                                        /* hop into C */
  224.         if (videomode&PAGE1) {            /* if page one selected, plot text */
  225.           if (!TextPlot(scrch,ea)) LoPlot(scrch,ea) ;
  226.         }
  227.   asm {                                    /* hop out of C, whee! */
  228.         LOADREGS                           /* restore 6502 enviornment */
  229.         JMP     (REGEMUL)    /* write-only routines go straight to emul */
  230.  
  231.   w0800:     /* handler for text page 2 - similar to above */
  232.         SWAP    DBUS
  233.         MOVE.L  REGEA,REGMEA
  234.         MOVE.B  DBUS,(REGMEA)
  235.         MOVE.B  DBUS,scrch(GLOBAL)
  236.  
  237.         MOVE.W  REGEA,ea(GLOBAL)
  238.         SAVEREGS
  239.   }
  240.         if (videomode&PAGE2) TextPlot(scrch,ea) ;
  241.   asm {
  242.         LOADREGS
  243.         JMP     (REGEMUL)    /* write-only routines go straight to emul */
  244.  
  245.   w2000:     /* handler for hires page 1 */
  246.         SWAP    DBUS                       /* get byte */
  247.         MOVE.L  REGEA,REGMEA
  248.         MOVE.B  DBUS,(REGMEA)              /* do the actual write to memory */
  249.         MOVE.B  DBUS,scrch(GLOBAL)         /* and to global variable */
  250.         MOVE.W  REGEA,ea(GLOBAL)           /* let C know where to write */
  251.         SAVEREGS                           /* save 6502 enviornment */
  252.   }                                        /* hop into C */
  253.         if (videomode&PAGE1)               /* if corrrect display is on */
  254.           HiPlot (scrch,ea) ;              /* plot the byte */
  255.   asm {                                    /* hop out of C, whee! */
  256.         LOADREGS                           /* restore 6502 enviornment */
  257.         JMP     (REGEMUL)    /* write-only routines go straight to emul */
  258.  
  259.  
  260.   w4000:     /* handler for hires page 2 - similar to above */
  261.         SWAP    DBUS
  262.         MOVE.L  REGEA,REGMEA
  263.         MOVE.B  DBUS,(REGMEA)
  264.         MOVE.B  DBUS,scrch(GLOBAL)
  265.         MOVE.W  REGEA,ea(GLOBAL)
  266.         SAVEREGS
  267.   }
  268.         if (videomode&PAGE2)
  269.           HiPlot (scrch,ea) ;
  270.   asm {
  271.         LOADREGS
  272.         JMP     (REGEMUL)
  273.  
  274.   sC000:
  275.         TESTWRITE
  276.         BEQ      C000write
  277.         SAVEREGS
  278.   }
  279.         if (Bconstat(2) != 0) {
  280.            *(mem+0xC000) = keyboard = Bconin(2)|0x80 ;
  281.           }
  282.   asm {
  283.         LOADREGS
  284.         RTS
  285.   C000write:                 /* can't write to keyboard */
  286.         JMP     (REGEMUL)
  287.  
  288.   sC010:
  289.         ANDI.B   #0x7F,keyboard(GLOBAL)    /* turn off high bit of keyboard */
  290.         MOVE.L   mem(GLOBAL),REGMEA
  291.         ADDA.L   #0xC000L,REGMEA
  292.         MOVE.B   keyboard(GLOBAL),(REGMEA)  /* write it to memory */
  293.         TESTWRITE
  294.         BEQ      C010write
  295.         RTS
  296.   C010write:
  297.         JMP     (REGEMUL)
  298.  
  299.   sC030:
  300.         SAVEREGS
  301.   }
  302.         tempsound = Giaccess(0,7) ;
  303.         Giaccess(55,128+7) ;
  304.         Giaccess(5,128+6)  ;
  305.         Giaccess(16,128+8) ;
  306.         Giaccess(1,128+11) ;
  307.         Giaccess(0,128+12) ;
  308.         Giaccess(0,128+13) ;
  309.         Giaccess(63,128+7) ;
  310.         Giaccess(tempsound,128+7) ;
  311.   asm {
  312.         LOADREGS
  313.         TESTWRITE
  314.         BEQ      C030write
  315.         RTS
  316.   C030write:
  317.         JMP     (REGEMUL)
  318.  
  319.   sC050:
  320.         ANDI.W   #~TEXT,videomode(GLOBAL)
  321.         ORI.W    #GRAPHICS,videomode(GLOBAL)
  322.         TESTWRITE
  323.         BEQ      C050write
  324.         RTS
  325.   C050write:
  326.         JMP     (REGEMUL)
  327.  
  328.   sC051:
  329.         ANDI.W   #~GRAPHICS,videomode(GLOBAL)
  330.         ORI.W    #TEXT,videomode(GLOBAL)
  331.         TESTWRITE
  332.         BEQ      C051write
  333.         RTS
  334.   C051write:
  335.         JMP     (REGEMUL)
  336.  
  337.   sC052:
  338.         ANDI.W   #~SPLITSCR,videomode(GLOBAL)
  339.         ORI.W    #FULLGRAF,videomode(GLOBAL)
  340.         TESTWRITE
  341.         BEQ      C052write
  342.         RTS
  343.   C052write:
  344.         JMP     (REGEMUL)
  345.  
  346.   sC053:
  347.         ANDI.W   #~FULLGRAF,videomode(GLOBAL)
  348.         ORI.W    #SPLITSCR,videomode(GLOBAL)
  349.         TESTWRITE
  350.         BEQ      C053write
  351.         RTS
  352.   C053write:
  353.         JMP     (REGEMUL)
  354.  
  355.   sC054:
  356.         ANDI.W   #~PAGE2,videomode(GLOBAL)
  357.         ORI.W    #PAGE1,videomode(GLOBAL)
  358.         TESTWRITE
  359.         BEQ      C054write
  360.         RTS
  361.   C054write:
  362.         JMP     (REGEMUL)
  363.  
  364.   sC055:
  365.         ANDI.W   #~PAGE1,videomode(GLOBAL)
  366.         ORI.W    #PAGE2,videomode(GLOBAL)
  367.         TESTWRITE
  368.         BEQ      C055write
  369.         RTS
  370.   C055write:
  371.         JMP     (REGEMUL)
  372.  
  373.   sC056:
  374.         ANDI.W   #~HIRES,videomode(GLOBAL)
  375.         ORI.W    #LORES,videomode(GLOBAL)
  376.         SAVEREGS
  377.   }
  378.         colors16() ;       /* set 16 color palette */
  379.   asm {
  380.         LOADREGS
  381.  
  382.         TESTWRITE
  383.         BEQ      C056write
  384.         RTS
  385.   C056write:
  386.         JMP     (REGEMUL)
  387.  
  388.   sC057:
  389.         ANDI.W   #~LORES,videomode(GLOBAL)
  390.         ORI.W    #HIRES,videomode(GLOBAL)
  391.         SAVEREGS
  392.   }
  393.         colors8() ;          /* set 6 color palette */
  394.   asm {
  395.         LOADREGS
  396.         TESTWRITE
  397.         BEQ      C057write
  398.         RTS
  399.   C057write:
  400.         JMP     (REGEMUL)
  401.  
  402.    }
  403.  }
  404.  
  405. /* text plotting routines to bypass GEM */
  406.  
  407. InitPrint ()  {
  408.  
  409.   long fontptr[4] ;
  410.   long *fonts ;
  411.   int *header ;
  412.   int x ;
  413.  
  414.   asm {
  415.          DC.W    0xA000
  416.          MOVE.L  A1,fonts(A6)
  417.       }
  418.  
  419.   for (x=0; x<3; x++) fontptr[x] = *fonts++ ;
  420.   header = (int*) fontptr[1] ;                /* header for 8x8 system font */
  421.   font = (char *) (header[38]*65536L+header[39]) ;
  422. }
  423.  
  424. TextPlot (text,loc)
  425.    int text ;
  426.    register int loc ;
  427.    {
  428.  
  429.   register int smask, scrx, scry ;
  430.   register char *newscr = scr_emul , *newfont = font ;
  431.  
  432.   if ((videomode&TEXT)||(videomode&SPLITSCR))  /* if we are in text mode */
  433.    {
  434.      loc &= 1023 ;  /* convert to relative offset from start of screen */
  435.      scry = (((loc&0x7F)/40)<<3) + (loc>>7) ; /* screen row */
  436.      scrx = (loc&0x7F)%40 ;                   /* screen column */
  437.  
  438.      newfont += ((text&0x80) ? text : (text^0x20)+0xA0 ) & 0x7F ;
  439.  
  440.      if (!((videomode&SPLITSCR)&&(scry<20)&&!(videomode&TEXT))) {
  441.  
  442.        switch (mode) {
  443.  
  444.          case 0 :
  445.              newscr += baddr1[scry] + (scrx&1) + ((scrx&~1)<<2) ;
  446.              smask = (text&0x80) ? 0 : ~0 ;
  447.              newscr[000] = newscr[002] = newscr[004] =
  448.              newscr[006] = newfont[0]^smask ;
  449.              newscr[160] = newscr[162] = newscr[164] =
  450.              newscr[166] = newfont[256]^smask ;
  451.              newscr[320] = newscr[322] = newscr[324] =
  452.              newscr[326] = newfont[512]^smask ;
  453.              newscr[480] = newscr[482] = newscr[484] =
  454.              newscr[486] = newfont[768]^smask ;
  455.              newscr[640] = newscr[642] = newscr[644] =
  456.              newscr[646] = newfont[1024]^smask ;
  457.              newscr[800] = newscr[802] = newscr[804] =
  458.              newscr[806] = newfont[1280]^smask ;
  459.              newscr[960] = newscr[962] = newscr[964] =
  460.              newscr[966] = newfont[1536]^smask ;
  461.              newscr[1120] = newscr[1122] = newscr[1124] =
  462.              newscr[1126] = newfont[1792]^smask ;
  463.              break ;
  464.  
  465.          case 1 :
  466.              newscr += baddr1[scry] + (scrx&1) + ((scrx&~1)<<1) + 40;
  467.              smask = (text&0x80) ? ~0 : 0 ;
  468.              newscr[000] = ( newscr[002] = newfont[000]^smask ) ;
  469.              newscr[160] = ( newscr[162] = newfont[256]^smask ) ;
  470.              newscr[320] = ( newscr[322] = newfont[512]^smask ) ;
  471.              newscr[480] = ( newscr[482] = newfont[768]^smask ) ;
  472.              newscr[640] = ( newscr[642] = newfont[1024]^smask) ;
  473.              newscr[800] = ( newscr[802] = newfont[1280]^smask) ;
  474.              newscr[960] = ( newscr[962] = newfont[1536]^smask) ;
  475.              newscr[1120]= ( newscr[1122]= newfont[1792]^smask) ;
  476.              break ;
  477.  
  478.          case 2 :
  479.              newscr += baddr2[scry] + scrx + 1220 ;
  480.              smask = (text&0x80) ? ~0 : 0 ;
  481.              newscr[0] = newfont[0]^smask ;
  482.              newscr[80] = newfont[256]^smask ;
  483.              newscr[160] = newfont[512]^smask ;
  484.              newscr[240] = newfont[768]^smask ;
  485.              newscr[320] = newfont[1024]^smask ;
  486.              newscr[400] = newfont[1280]^smask ;
  487.              newscr[480] = newfont[1536]^smask ;
  488.              newscr[560] = newfont[1792]^smask ;
  489.        }
  490.        return(1) ;
  491.      }
  492.   }
  493.   return(0) ;    /* unsuccesful plot */
  494. }
  495.  
  496. LoPlot (text,loc)
  497.    register int text, loc ;
  498.    {
  499.  
  500.   register int scrx, scry, temp ;
  501.   register char *newscr = scr_emul ;
  502.  
  503.   loc &= 1023 ;  /* convert to relative offset from start of screen */
  504.   scry = (((loc&0x7F)/40)<<3) + (loc>>7) ; /* screen row */
  505.   scrx = (loc&0x7F)%40 ;                   /* screen column */
  506.  
  507.   if (videomode&LORES)
  508.     switch (mode) {
  509.  
  510.        case 0 :
  511.              newscr += baddr1[scry] + (scrx&1) + ((scrx&~1)<<2) ;
  512.              newscr[000] = newscr[160] = newscr[320] =
  513.              newscr[480] = (text&1) ? ~0 : 0 ;
  514.              newscr[002] = newscr[162] = newscr[322] =
  515.              newscr[482] = (text&2) ? ~0 : 0 ;
  516.              newscr[004] = newscr[164] = newscr[324] =
  517.              newscr[484] = (text&4) ? ~0 : 0 ;
  518.              newscr[006] = newscr[166] = newscr[326] =
  519.              newscr[486] = (text&8) ? ~0 : 0 ;
  520.              newscr[640] = newscr[800] = newscr[960] =
  521.              newscr[1120] = (text&16) ? ~0 : 0 ;
  522.              newscr[642] = newscr[802] = newscr[962] =
  523.              newscr[1122] = (text&32) ? ~0 : 0 ;
  524.              newscr[644] = newscr[804] = newscr[964] =
  525.              newscr[1124] = (text&64) ? ~0 : 0 ;
  526.              newscr[646] = newscr[806] = newscr[966] =
  527.              newscr[1126] = (text&128) ? ~0 : 0 ;
  528.              break ;
  529.  
  530.          case 1 :
  531.              newscr += baddr1[scry] + (scrx&1) + ((scrx&~1)<<1) + 40;
  532.              newscr[000] = newscr[002] =
  533.              newscr[160] = newscr[162] =
  534.              newscr[320] = newscr[322] =
  535.              newscr[480] = newscr[482] = ~((text&0x0F)|((text&0x0f)<<4)) ;
  536.              newscr[640] = newscr[642] =
  537.              newscr[800] = newscr[802] =
  538.              newscr[960] = newscr[962] =
  539.              newscr[1120]= newscr[1122] = ~((text&0xF0)|((text&0xF0)>>4)) ;
  540.              break ;
  541.  
  542.          case 2 :
  543.              newscr += baddr2[scry] + scrx + 1220 ;
  544.              newscr[0] = newscr[80] = newscr[160] = newscr[240] =
  545.                ~((text&0x0F)|((text&0x0f)<<4)) ;
  546.              newscr[320] = newscr[400] = newscr[480] = newscr[560] =
  547.                ~((text&0xF0)|((text&0xF0)>>4)) ;
  548.  
  549.      }
  550. }
  551.  
  552. HiPlot (byt,loc)       /* hi-res poking */
  553.   register int byt, loc ;
  554.  {
  555.   register int scrx, scry ;
  556.   register char *tempscr ;
  557.   int bitmsk ;
  558.  
  559.   if (videomode&GRAPHICS)     /* if we are in graphics mode */
  560.     {
  561.      loc &= 8191 ;  /* convert to relative offset from start of screen */
  562.      scry = ( ((((loc&0x7F)/40)<<3)+((loc&0x3FF)>>7) )<<3)
  563.              + (loc>>10) ;             /* calculate screen row */
  564.  
  565.      scrx = (loc&0x7F)%40 ;                   /* screen column */
  566.  
  567.      bitmsk = (scrx&1) + (byt&0x80) ;
  568.  
  569.                        /* quickly reverse the order of the bits in byt */
  570.   asm {
  571.        CLR.W    D0
  572.        ROXR.B   #1,byt
  573.        ROXL.B   #1,D0
  574.        ROXR.B   #1,byt
  575.        ROXL.B   #1,D0
  576.        ROXR.B   #1,byt
  577.        ROXL.B   #1,D0
  578.        ROXR.B   #1,byt
  579.        ROXL.B   #1,D0
  580.        ROXR.B   #1,byt
  581.        ROXL.B   #1,D0
  582.        ROXR.B   #1,byt
  583.        ROXL.B   #1,D0
  584.        ROXR.B   #1,byt
  585.        ROXL.B   #1,D0
  586.        MOVE.B   D0,byt
  587.       }
  588.  
  589.      if (!((videomode&SPLITSCR)&&(scry>159))) {
  590.  
  591.        switch (mode) {
  592.  
  593.         case 2 :
  594.              scr_emul[scry*80+scrx+1220] = ~byt ;
  595.              break ;
  596.         case 0 :
  597.              tempscr = &scr_emul[scry*160 + (scrx&1) + ((scrx&~1)<<2)] ;
  598.              tempscr[6] = (bitmsk&0x80) ? byt : 0 ;
  599.              tempscr[4] = byt&0x2A ;
  600.              tempscr[2] = byt&0x55 ;
  601.              tempscr[0] = (bitmsk&1) ? byt : 0 ;
  602.              break ;
  603.         case 1 :
  604.              tempscr = &scr_emul[scry*160 + (scrx&1) + ((scrx&~1)<<1) + 40] ;
  605.              tempscr[0] = tempscr[2] = ~byt ;
  606.              break ;
  607.          }
  608.        return (1) ;
  609.        }
  610.   }
  611.   return(0) ;
  612. }
  613.  
  614.  
  615.